/*********************************************************
          File Name:8.4.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 14 Sep 2015 10:38:52 AM CST
**********************************************************/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using std::string;
using std::vector;
using std::ifstream;


void fun(const string &file)
{
        vector<string> fv;
        string line;

        ifstream ifs(file);

        if(ifs)
        {
                while(std::getline(ifs, line))
                        fv.push_back(line);

        ifs.close();
        std::cout << std::unitbuf;

        for(auto c: fv)
                std::cout << c << std::endl;
        }
        else
        {
                std::cout << ifs.rdstate() << std::endl;
        }
}

int main(int argc, char *argv[])
{
        if(argc != 2)
        {
                std::cerr << argv[0] << " filename" << std::endl;
                std::cerr << "file must exist and has contents" << std::endl;
                exit(1);
        }

        fun(argv[1]);

        return 0;
}
